package com.hy.mydesktop.client.rpc.reader;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import com.extjs.gxt.ui.client.data.BaseModel;
import com.extjs.gxt.ui.client.data.DataReader;
import com.extjs.gxt.ui.client.data.ListLoadResult;
import com.extjs.gxt.ui.client.data.ModelData;
import com.hy.mydesktop.shared.rpc.meta.GxtToSeamServiceResult;
import com.hy.mydesktop.shared.rpc.meta.GxtToSeamServiceTreeNode;
import com.hy.mydesktop.shared.util.log.MyLoggerUtil;

/**
 * 
 * <ul>
 * <li>开发作者：花宏宇</li>
 * <li>设计日期：2010-10-9；时间：下午05:33:08</li>
 * <li>类型名称：GxtToSeamServiceResultReader</li>
 * <li>设计目的：用于解析GxtToSeamServiceResult的DataReader</li>
 * </ul>
 * <ul>
 * <b>修订编号：</b>
 * <li>修订日期：</li>
 * <li>修订作者：</li>
 * <li>修订原因：</li>
 * <li>修订内容：</li>
 * </ul>
 */
public class GxtToSeamServiceResultListReader<D> implements DataReader<D> {
	//private static GxtToSeamServiceResultListReader<GxtToSeamServiceResult> listreader = new GxtToSeamServiceResultListReader<GxtToSeamServiceResult>();
	
	@Override
	public D read(Object loadConfig, Object data) {
		//data是Rpc调用后的返回值result
		MyLoggerUtil.printError(GxtToSeamServiceResultListReader.class,"####GxtToSeamServiceResultListReader.read() is running...........................");
		if (data==null) {
			return null;			
		}
		if (data instanceof GxtToSeamServiceResult) {
			GxtToSeamServiceResult gxtToSeamServiceResult =(GxtToSeamServiceResult)data;
			//System.err.println("GxtToSeamServiceResultReader.read() is running..............GxtToSeamServiceResult.............");
			ModelData modelData = gxtToSeamServiceResult.getResult();
			Collection<ModelData> modelDatas = (Collection<ModelData>)modelData.get("listOfModelData");
			BaseModel tempmModelData=null;
			for (ModelData subModelData : modelDatas) {
				tempmModelData=(BaseModel)subModelData;
				MyLoggerUtil.printDebug(GxtToSeamServiceResultListReader.class,"gxtToSeamServiceResult.getResult()========modelData.get(listOfModelData)"+subModelData);				
			}
			MyLoggerUtil.printErrorForBaseModelAttributes(GxtToSeamServiceResultListReader.class,tempmModelData);

			
			//BaseListLoadConfig
			MyLoggerUtil.printError(GxtToSeamServiceResultListReader.class,"GxtToSeamServiceResultReader.read().loadConfig is ######"+loadConfig);
			//loadConfig = null;
			//System.out.println("GxtToSeamServiceResultReader.read().loadConfig is ######"+loadConfig);
			MyLoggerUtil.printError(GxtToSeamServiceResultListReader.class,"####GxtToSeamServiceResultListReader.read() is over...........................");
			return (D)(gxtToSeamServiceResult.getResult().get("listOfModelData"));
			
			/*String config = null;
			  if (loadConfig==null) {
				return (D)(gxtToSeamServiceResult.getResult().get("listOfModelData"));
			}else if (loadConfig instanceof String) {
				config = (String)loadConfig;
				System.err.println("GxtToSeamServiceResultReader.read().loadConfig @@@@@@@@@@@"+config);
				//return (D)(gxtToSeamServiceResult.getResult().get(config));
				return (D)(gxtToSeamServiceResult.getResult().get("listOfModelData"));
			}else {
				return (D)(gxtToSeamServiceResult.getResult().get("listOfModelData"));
			}*/
			
		} 
		assert false : "Error converting data";
		return null;
	}
	
}
